package leetcode.stack;

import java.util.*;

public class MinStack {
    Stack<Integer> integer = new Stack<>();
    Stack<Integer> minlist = new Stack<>();
    /** initialize your data structure here. */
    public MinStack() {
        //栈，后入先出
    }

    public void push(int x) {

        integer.push(x);
        int min = fuzu();
        minlist.push(min);
    }

    public void pop() {
        integer.pop();
        minlist.pop();
    }

    public int top() {
        return integer.peek();
    }

    public Integer min(){
//        if(minlist.empty()==true){
//            return null;
//        }
        return minlist.peek();
    }

    public int fuzu() {
        Stack<Integer> integer1 = (Stack<Integer>) integer.clone();
        int min = integer1.peek();
        int temp = 0;
        while(integer1.empty()==false){
            temp = integer1.pop();
            if (temp<min){
                min = temp;
            }
        }
        return min;
    }
}

